#include <QDebug>
#include <QString>

#include "scheduler.h"
#include "netter.h"

Scheduler::Scheduler(QObject *parent) :
    QThread(parent) {
		
}

void Scheduler::run() {
	
	// valuto la presenza di nuovi comandi
	// nella queue
	while (!QThread::isFinished()) {
		mutex.lock();
		if (!messageQueue.isEmpty()) {
			qDebug() << "Nuovo comando";
			
			Message *c = messageQueue.dequeue();
			//qDebug() << c->msg;
			
			emit eventNewCommand(c);
			qDebug() << "Rimozione comando";
			delete c;
		}
		mutex.unlock();	
		QThread::msleep(100);	// 10 millisecondi

	}
	
	qDebug() << "Scheduler terminato";

}

void Scheduler::pushNewCommand(Message *c) {
	
	mutex.lock();
	messageQueue.enqueue(c);
	mutex.unlock();
	
}


